﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("BE")]
namespace DAL.DataFramework
{
    public class ConnectionsDAL<T> :IDisposable
    {
        string CreateGUID = "80C6CA10-56D9-407B-BFA6-29ABE3B8874F";
        string UpdateGUID = "C1F6DA4D-4F5A-4B69-A798-FADC2A47C7F1";
        string DeleteGUID = "DD81E4D6-15EA-44EE-9713-FC33B54764A4";
        string SelectGUID = "B4A3CBBA-362C-48EE-95F0-F9A0DD073617";

        internal T Create(string sConnectionName, int iConnectorId, string sConnectionString, bool bActive)
        {
            try
            {
                T result;
                result = new GenericList<T>().GetAGenelicListOf(
                    DAL.Gateway.DataAccessGateway.TraerDataTable(CreateGUID,
                    sConnectionName,
                    iConnectorId,
                    sConnectionString,
                    bActive)).Single<T>();
                return result;
            }
            catch(Exception ex)
            {
                throw new Exception("ConnectionsDAL - Create - ",ex);
            }
        }
        internal T Update(int iConnectionId, string sConnectionName, int iConnectorId, string sConnectionString, bool bActive)
        {
            try
            {
                T result;
                result = new GenericList<T>().GetAGenelicListOf(
                    DAL.Gateway.DataAccessGateway.TraerDataTable(UpdateGUID,
                    iConnectionId,
                    sConnectionName,
                    iConnectorId,
                    sConnectionString,
                    bActive)).Single<T>();
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsDAL - Update - ", ex);
            }
        }
        internal List<T> Select(int iConnectionId, string sConnectionName, int iConnectorId, string sConnectionString, bool bActive)
        {
            try
            {
            List<T> result = new List<T>();
                result = new GenericList<T>().GetAGenelicListOf(
                    DAL.Gateway.DataAccessGateway.TraerDataTable(SelectGUID,
                    iConnectionId,
                    sConnectionName,
                    iConnectorId,
                    sConnectionString,
                    bActive)).ToList<T>();
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsDAL - Update - ", ex);
            }
        }
        internal int Delete(int iConnectionId)
        {
            try
            {
                int result= 0;

                result = DAL.Gateway.DataAccessGateway.Ejecutar(DeleteGUID, iConnectionId);

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectionsDAL - Delete - ", ex);
            }
        }
        public void Dispose()
        {
        }
    }
}
